package com.etone.fileServer.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.Map;

/**
 * @author: sovy
 * @date: 2020/11/25
 * @description:
 */
public class ObjectUtil {

    /**
     * bean转map
     *
     * @param obj
     * @return
     */
    public static Map<String, Object> toMap(Object obj) {
        String jsonString = JSONObject.toJSONString(obj);
        Map<String, Object> map = JSONObject.parseObject(jsonString, Map.class);
        return map;
    }

    /**
     * 判断是否是基本类型
     *
     * @param object
     * @return
     */
    public static boolean isBaseType(Object object) {
        Class className = object.getClass();
        return className.equals(java.lang.Integer.class) ||
                className.equals(java.lang.String.class) ||
                className.equals(java.lang.Byte.class) ||
                className.equals(java.lang.Long.class) ||
                className.equals(java.lang.Double.class) ||
                className.equals(java.lang.Float.class) ||
                className.equals(java.lang.Character.class) ||
                className.equals(java.lang.Short.class) ||
                className.equals(java.lang.Boolean.class);

    }
}
